// ==UserScript==
// @name         Add to Music Player
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  添加当前页面到音乐播放器
// @author       You
// @match        *://*/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

    const btn = document.createElement('button');
    btn.innerHTML = '🎵 添加此页面';
    btn.style.cssText = `
        position: fixed;
        top: 20px;
        right: 20px;
        z-index: 9999;
        padding: 10px 15px;
        background: #2196F3;
        color: white;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    `;

    btn.addEventListener('click', () => {
        GM_xmlhttpRequest({
            method: 'POST',
            url: 'http://192.168.238.28:5000/add_song_from_client',
            data: JSON.stringify({
                type: 'url',
                url: window.location.href
            }),
            headers: {
                'Content-Type': 'application/json'
            },
            onload: (res) => {
                alert(res.status === 200 ? '添加成功！' : '添加失败');
            }
        });
    });

    document.body.appendChild(btn);
})();